package com.hjtm.easypigfarm.fragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import com.hjtm.easypigfarm.R;
import com.hjtm.easypigfarm.utility.Constants;

// yingkui he suan
public class FragmentCostEarn extends Fragment {

    /*private final String TITLE_TAG = "title";
    private final String VALUE_TAG = "value";*/

    private List<HashMap<String, Object>> mCost = new ArrayList<HashMap<String, Object>>();

    GridView mGv2;
    Context mContext;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initData();
    }

    private void initData() {
        mCost.clear();
        HashMap<String, Object> map = new HashMap<String, Object>();

        map.put(Constants.TITLE_TAG, "Incoming");
        map.put(Constants.VALUE_TAG, "12213");
        mCost.add(map);

        HashMap<String, Object> map2 = new HashMap<String, Object>();

        map2.put(Constants.TITLE_TAG, "Earning");
        map2.put(Constants.VALUE_TAG, 10223.1);
        mCost.add(map2);

        HashMap<String, Object> map3 = new HashMap<String, Object>();

        map3.put(Constants.TITLE_TAG, "Incoming2");
        map3.put(Constants.VALUE_TAG, "12213");
        mCost.add(map3);

        HashMap<String, Object> map4 = new HashMap<String, Object>();

        map4.put(Constants.TITLE_TAG, "Earning2");
        map4.put(Constants.VALUE_TAG, 9883.1);
        mCost.add(map4);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.address, null);
        mContext = getActivity();

        mGv2 = (GridView) v.findViewById(R.id.gridView2);
        String[] from = { Constants.TITLE_TAG, Constants.VALUE_TAG };
        int[] to = { R.id.item, R.id.value };
        SimpleAdapter adapter2 = new SimpleAdapter(mContext, mCost,
                R.layout.list_item_value, from, to);
        mGv2.setAdapter(adapter2);
        return v;
    }

}
